import axios from 'axios'

axios.defaults.baseURL = 'http://localhost:8888/api/private/v1/'
// Add a request interceptor
axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  console.log(config)
  let token = localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

export const login = (obj) => axios.post('login', obj)
// export const login = function (obj) {
//   return axios.post('login', obj)
// }
// 用户数据列表获取
export const homeData = obj => axios.get('users', { params: obj })
// 添加用户
export const addUser = obj => axios.post('users', obj)
// 删除用户
export const delUser = id => axios.delete(`users/${id}`)
// 编辑用户
export const editUser = obj => axios.put(`users/${obj.id}`, obj)
// 改变用户状态
export const changeUserState = (uid, type) => axios.put(`users/${uid}/state/${type}`)
// 权限下拉菜单
export const selectList = () => axios.get(`roles`)
// 提交权限更改
export const uploadSelect = (id, rid) => axios.put(`users/${id}/role`, { rid: rid })
// 权限管理列表
export const powerList = type => axios.get(`rights/${type}`)
// 删除角色指定权限
export const delUserRight = (roleId, rightId) => axios.delete(`roles/${roleId}/rights/${rightId}`)
// 编辑提交角色
export const uploadUsersRight = (id, obj) => axios.put(`roles/${id}`, obj)
// 添加角色
export const addUserRight = obj => axios.post(`roles`, obj)
// 删除角色
export const delUserListRight = id => axios.delete(`roles/${id}`)
// 角色授权
export const addRight = (roleId, rids) => axios.post(`roles/${roleId}/rights`, { rids })
// 左侧菜单
export const asideLeft = () => axios.get(`menus`)
// 商品分类列表
export const cateList = obj => axios.get(`categories`, { params: obj })
// 添加分类
export const addCateList = obj => axios.post(`categories`, obj)
// 删除分类
export const delCate = id => axios.delete(`categories/${id}`)
// 根据id查询分类
export const idSearch = id => axios.get(`categories/${id}`)
// 编辑提交分类
export const uploadEditKind = (id, kindName) => axios.put(`categories/${id}`, { cat_name: kindName })
